package com.itheima.tanhua.web;

import com.itheima.tanhua.service.MessagesService;
import com.itheima.tanhua.vo.mongo.UserInfoVo;
import com.itheima.tanhua.vo.mongo.pageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author 芝士雪豹
 * @create 2022/9/28/17:43
 */
@RestController
@RequestMapping("messages")
public class MessagesController {
    @Autowired
    private MessagesService service;

    //根据环信id查询对应用户信息
    @GetMapping("userinfo")
    public ResponseEntity userinfo(String huanxinId) {
        UserInfoVo vo = service.findUserinfoByHuanxin(huanxinId);
        return ResponseEntity.ok(vo);
    }

    //添加好友
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map) {
        Long friendId = Long.valueOf(map.get("userId").toString());
        service.contacts(friendId);
        return ResponseEntity.ok(null);
    }
    //查询联系人列表
    @GetMapping("contacts")
    public ResponseEntity findByUserId(
            @RequestParam(value = "1") Integer page,
            @RequestParam(value = "10") Integer pagesize,
            String keyword) {
        pageResult ps = service.findByFriend(page, pagesize,keyword);
        return ResponseEntity.ok(ps);
    }
}
